package scribble;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.*;
import javax.swing.border.LineBorder;

public class Scribble extends JFrame {

	JPanel panel;
	static Color linecolor = Color.black;

	public Scribble() {
		setLayout(null);

		panel = new JPanel();
		panel.setBounds(10, 10, 600, 450);
		panel.setBorder(new LineBorder(Color.blue));

		panel.addMouseMotionListener(new MouseAdapter() {
			@Override
			public void mouseDragged(MouseEvent e) {
				Graphics2D g = (Graphics2D) panel.getGraphics();
				g.setColor(linecolor);
				colorChange();
				g.drawLine(0, 0, e.getX(), e.getY());
				g.dispose();
			}
		});

		add(panel);
		setVisible(true);
		setSize(700, 500);

		setDefaultCloseOperation(EXIT_ON_CLOSE);

	}

	public void colorChange() {
		int r = linecolor.getRed();
		int g = linecolor.getGreen();
		int b = linecolor.getBlue();
		if (r < 255)
			r++;
		if (r == 255 & g < 255)
			g++;
		if (g == 255 & b < 255)
			b++;
		if (b == 255) {
			r = g = b = 0;
		}
		linecolor = new Color(r, g, b);
	}

	public static void main(String[] args) {
		Scribble s = new Scribble();
	}

}
